app.controller('pv3', function ($scope, $rootScope, $http, $interval, $compile, $state) {
    //pv任务
    $scope.pv1 = function () {
        $state.go(pv1_0.stateName);
    }
    //开始工作
    $scope.pv7 = function () {
        localStorage.setItem("pv-lastOcrUsageInfoPage",JSON.stringify($scope.ocrUsageInfoPage));
        pv7.params.caseId = $scope.id;
        pv7.params.address = $scope.pvCase.address;
        pv7.params.productName = $scope.productName;
        localStorage.setItem("pv-caseId",$scope.id);
        localStorage.setItem("pv-isfond",1); //点击开始工作，默认找到打印机

        localStorage.removeItem("pv-feSignUrl");
        localStorage.removeItem("pv-customerSignUrl");
        localStorage.removeItem("pv-ocrUsageInfoPage");
        localStorage.removeItem("pv-countfeSignUrl");
        localStorage.removeItem("pv-countcustomerSignUrl");

        $state.go(pv7.stateName);
    }

    //工作人员签字
    $scope.pv11 = function (type) {
        if($scope.pvCase.status!=4){
            $rootScope.tipPopups.show(($rootScope.tipMessage = "该任务暂不能进行签字"));
            return;
        }

        if(!$scope.ocrUsageInfoPage){
            $rootScope.tipPopups.show(($rootScope.tipMessage = "用量信息页为空，不能进行签字"));
        }
        /*if(!$scope.ocrUsageInfoPage.current.totalMono || !$scope.ocrUsageInfoPage.current.totalColor || !$scope.ocrUsageInfoPage.current.monochrome
            || !$scope.ocrUsageInfoPage.current.accent || !$scope.ocrUsageInfoPage.current.generalOffice || !$scope.ocrUsageInfoPage.current.other){
            $rootScope.tipPopups.show(($rootScope.tipMessage = "用量信息页为空，不能进行签字"));
            return;
        }*/

        if(!$scope.ocrUsageInfoPage.current || ($scope.ocrUsageInfoPage.current.totalMono==="" ||
            $scope.ocrUsageInfoPage.current.totalColor==="" || $scope.ocrUsageInfoPage.current.monochrome===""
            || $scope.ocrUsageInfoPage.current.accent==="" || $scope.ocrUsageInfoPage.current.generalOffice==="" || $scope.ocrUsageInfoPage.current.other==="")){
            $rootScope.tipPopups.show(($rootScope.tipMessage = "用量信息页为空，不能进行签字"));
            return;
        }

        pv11.params.type = type;
        pv11.params.caseId = $scope.id;

        localStorage.setItem("pv-type",type);
        localStorage.setItem("pv-caseId",$scope.id);
        $state.go(pv11.stateName);
    }
    //客户是否签字
    $scope.pv12 = function () {
        $state.go(pv12.stateName);
    }

    //显示图片
    $scope.viewerImg = function(index,objectArray){

        // jquery weui 图片浏览器  不能看长图
        if (!objectArray || objectArray.length == 0) return false;
        var images = [];
        for (var i in objectArray) {
            if (objectArray[i])
                images.push(objectArray[i]);
        }
        if (images.length == 0) return false;
        var pb = $.photoBrowser({
            items: images,
            initIndex: index,
            onOpen: function () {
                console.log(this);
            }
        });
        // pb.currentScale = 2;
        pb.open();  //打开
    }

    //获得数据
    $scope.getOrders = function () {
        if(!$scope.id){
         return;
         }
        var postData = {};
        getHttp($http, 'pvCase/get?caseId='+$scope.id, postData, function (res) {
            if (res.code === 0 && res.msg == "success") {
                $scope.isOcr = res.isOcr;
                $scope.ocrUsageInfoPage = res.ocrUsageInfoPage;  //用量信息页数据
                $scope.ocrConfigPage = res.ocrConfigPage;  //配置页数据
                $scope.casePhoto = res.casePhoto;      //照片数据
                if($scope.casePhoto){
                    $scope.photourls = JSON.parse($scope.casePhoto.urls);
                }
                $scope.pvCase = res.pvCase;  //任务详情数据和打印机信息
                $scope.ocrStatusReportPage = res.ocrStatusReportPage;  //打印机状态报告数据&耗材状态页

                //产品名称
                if(res.pvCase.productInfo){
                     var temp = JSON.parse(res.pvCase.productInfo);
                     $scope.productName = temp[0].model;
                }

                $scope.fesignUrl = $scope.pvCase.feSignUrl;   //工程师签字
                $scope.customerSignUrl = $scope.pvCase.customerSignUrl;  //客户签字

                $scope.$applyAsync();
            } else {
                $rootScope.tipPopups.show(($scope.tipMessage = res.message));
            }
        });
    }

    $scope.transfer = function (json,value) {
        if(!json){
            return;
        }
        var obj = JSON.parse(json);
        return obj[0][value];
    }
    $scope.transferImg = function (json,value) {
        if(!json){
            return;
        }
        var obj = JSON.parse(json);
        return obj[value];
    }

    //初始化
    function init(){
        //案例id
        $scope.id = pv3_0.params.id;
        if(!pv3_0.params.id){
            $scope.id = localStorage.getItem("pv-caseId");
        }
        $scope.getOrders();

        //获得签名
        // $scope.fesignUrl = localStorage.getItem("pv-feSignUrl");
        // $scope.customerSignUrl = localStorage.getItem("pv-customerSignUrl");
    }

    init();


    reloadJs();

});